﻿using System;

using System.Collections.Generic;
using System.Text;
using System.IO;

namespace gpsmid_wince.util {
	class ContainerTile : Tile {
		private Logger logger = Logger.getInstance("ContainerTile", Logger.DEBUG);

		Tile t1;
		Tile t2;

		public ContainerTile(JavaDataInputStream dis, int deep,sbyte zl)  {
    		//#debug
       		//logger.debug("start "+deep);
    		minLat=dis.readFloat();
    		minLon=dis.readFloat();
    		maxLat=dis.readFloat();
    		maxLon=dis.readFloat();
			centerLat = (maxLat+minLat)/2;
			centerLon = (maxLon+minLon)/2;
    		//#debug
    		//logger.debug("start left "+deep);
    		t1=DictReader.readTile(dis,deep+1,zl);
    		//#debug
       		//logger.debug("start right "+deep);
       		t2=DictReader.readTile(dis,deep+1,zl);
			//#debug
    		//logger.debug("ready "+deep+":readed ContainerTile");
		}
		/*
		public Tile readTile(JavaDataInputStream dis, int deep, sbyte zl) {
    		sbyte t=dis.readByte();
    		switch (t) {
    			case Tile.TYPE_MAP:
    				//#debug
    				//logger.debug("r ST " + zl + " " + deep);
    				return new SingleTile(dis,deep,zl);
    			case Tile.TYPE_CONTAINER:
    				//#debug
    				//logger.debug("r CT " + zl + " " + deep);
    				return new ContainerTile(dis,deep,zl);
    			case Tile.TYPE_EMPTY:
    				//#debug
    				//logger.debug("r ET " + zl + " " + deep);
    				return null;
    			case Tile.TYPE_FILETILE:
    				//#debug
    				//logger.debug("r FT " + zl + " " + deep);
    				//return new FileTile(dis,deep,zl);
					break;
    			case Tile.TYPE_ROUTEFILE:
    				//#debug
    				//logger.debug("r RFT " + zl + " " + deep);
    				//return new RouteFileTile(dis,deep,zl);
					break;
    			default:
    				//#debug error
					logger.error("wrongTileType:"+t);
    				throw new IOException("wrong TileType:"+t);
    		}
			return null;
		}
		*/

		public override bool cleanup(int level) {return true;}

		public override void paint(PaintContext pc, sbyte layer) {
			if (contain(pc)) {
				if (t1 != null) t1.paint(pc, layer);
				if (t2 != null) t2.paint(pc, layer);
			} else {			
				cleanup(4);
			}
		}
		public override void walk(PaintContext pc,int opt) {

			if (contain(pc)){
				if (t1 != null) {
					t1.walk(pc,opt);
				}
				if (t2 != null) {
					t2.walk(pc,opt);
				}	
			} else {	
				cleanup(4);
			}
		}
	}
}
